import os
from typing import Any

from dotenv import load_dotenv


def getConfigData(key: str = "") -> Any:
    load_dotenv()
    return os.getenv(key)


def get_boolean_fun(key) -> bool:
    value: str = getConfigData(key)
    return value.lower() == "true" if value is not None else False


class Config:
    def __init__(self):
        self.SECRET_KEY =  "nihao6681"
        self.SESSION_COOKIE_NAME = 'session_id'
        self.PERMANENT_SESSION_LIFETIME = 604800
        self.WTF_CSRF_ENABLED = False
        self.SQLALCHEMY_DATABASE_URI = getConfigData("SQLALCHEMY_DATABASE_URI")
        self.SQLALCHEMY_ENGINE_OPTIONS = {
            "pool_size": getConfigData("SQLALCHEMY_POOL_SIZE"),
            "pool_recycle": getConfigData("SQLALCHEMY_POOL_RECYCLE")
        }


        self.SQLALCHEMY_ECHO = get_boolean_fun("SQLALCHEMY_ECHO")
        self.REDIS_HOST = getConfigData("REDIS_HOST")
        self.REDIS_PORT = getConfigData("REDIS_PORT")
        self.REDIS_USRNAME = getConfigData("REDIS_USRNAME")
        self.REDIS_PASSWORD = getConfigData("REDIS_PASSWORD")
        self.REDIS_DB = getConfigData("REDIS_DB")
        self.REDIS_USE_SSL = get_boolean_fun("REDIS_USE_SSL")
        self.SQLALCHEMY_POOL_TIMEOUT = getConfigData("SQLALCHEMY_POOL_TIMEOUT")
        # JWT 配置
        self.JWT_SECRET_KEY = "nihao6681"  # 用于加密 JWT
        self.JWT_EXPIRATION_DELTA = 604800  # JWT 过期时间：1小时
